Have PropertyDictionary and ItemDictionary implement ICollection<T>#12170
Merged
SimaTian merged 5 commits intodotnet:mainfrom Aug 25, 2025
Merged
Have PropertyDictionary and ItemDictionary implement ICollection<T>#12170SimaTian merged 5 commits intodotnet:mainfrom
SimaTian merged 5 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR extends PropertyDictionary<T> and ItemDictionary<T> to implement ICollection<T>, reducing unnecessary list allocations when interacting with backing collections.
- PropertyDictionary now explicitly implements
ICollection<T>methods. - ItemDictionary now implements
ICollection<T>, addingIsReadOnlyandCopyTo.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/Build/Collections/PropertyDictionary.cs | Added ICollection<T> to class signature and provided explicit interface members |
| src/Build/Collections/ItemDictionary.cs | Added ICollection<T> to class signature and implemented IsReadOnly and CopyTo methods |
…rndt/ICollectionPropertyDict
SimaTian
approved these changes
Aug 25, 2025
JanProvaznik
approved these changes
Aug 25, 2025
JanProvaznik
pushed a commit
that referenced
this pull request
Aug 26, 2025
…12170) Fixes # ### Context The `BackingCollection` property checks the backing collection for `ICollection<T>`. <img width="638" height="241" alt="image" src="https://github.com/user-attachments/assets/9012ec98-7ddf-4ad4-8c5f-30c5e4520666" /> This implementation creates a list copy if the underlying backing type doesn't implement `ICollection<T>`, and `PropertyDictionary` and `ItemDictionary` are two types that fall into this copying behavior. <img width="899" height="218" alt="image" src="https://github.com/user-attachments/assets/049fd288-c1cb-4920-8e6d-a9bbd46a8a76" /> This can be fixed by having them implement `ICollection<T>`. I don't see any allocations in this path after the change. ### Changes Made ### Testing ### Notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #
Context
The
BackingCollectionproperty checks the backing collection forICollection<T>.This implementation creates a list copy if the underlying backing type doesn't implement
ICollection<T>, andPropertyDictionaryandItemDictionaryare two types that fall into this copying behavior.This can be fixed by having them implement
ICollection<T>. I don't see any allocations in this path after the change.Changes Made
Testing
Notes